{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24679"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json\n",
    "pred_data_1=[]\n",
    "pred_num_1=0\n",
    "with open(\"./predict_res kg.json\",\"r\") as r:\n",
    "    raw_data=r.readlines()\n",
    "    for d in raw_data:\n",
    "        pred_data_1.append(json.loads(d))\n",
    "        pred_num_1+=len(pred_data_1[-1]['spo_list'])\n",
    "pred_num_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "code_folding": [
     1,
     11,
     34
    ]
   },
   "outputs": [],
   "source": [
    "import unicodedata\n",
    "def _is_whitespace(char):\n",
    "    \"\"\"Checks whether `chars` is a whitespace character.\"\"\"\n",
    "    # \\t, \\n, and \\r are technically contorl characters but we treat them\n",
    "    # as whitespace since they are generally considered as such.\n",
    "    if char == \" \" or char == \"\\t\" or char == \"\\n\" or char == \"\\r\":\n",
    "        return True\n",
    "    cat = unicodedata.category(char)\n",
    "    if cat == \"Zs\":\n",
    "        return True\n",
    "    return False\n",
    "def is_chinese_char(cp):\n",
    "    \"\"\"Checks whether CP is the codepoint of a CJK character.\"\"\"\n",
    "    # This defines a \"chinese character\" as anything in the CJK Unicode block:\n",
    "    #   https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)\n",
    "    #\n",
    "    # Note that the CJK Unicode block is NOT all Japanese and Korean characters,\n",
    "    # despite its name. The modern Korean Hangul alphabet is a different block,\n",
    "    # as is Japanese Hiragana and Katakana. Those alphabets are used to write\n",
    "    # space-separated words, so they are not treated specially and handled\n",
    "    # like the all of the other languages.\n",
    "    if (\n",
    "        (cp >= 0x4E00 and cp <= 0x9FFF)\n",
    "        or (cp >= 0x3400 and cp <= 0x4DBF)  #\n",
    "        or (cp >= 0x20000 and cp <= 0x2A6DF)  #\n",
    "        or (cp >= 0x2A700 and cp <= 0x2B73F)  #\n",
    "        or (cp >= 0x2B740 and cp <= 0x2B81F)  #\n",
    "        or (cp >= 0x2B820 and cp <= 0x2CEAF)  #\n",
    "        or (cp >= 0xF900 and cp <= 0xFAFF)\n",
    "        or (cp >= 0x2F800 and cp <= 0x2FA1F)  #\n",
    "    ):  #\n",
    "        return True\n",
    "\n",
    "    return False\n",
    "def is_punctuation(char):\n",
    "    \"\"\"Checks whether `chars` is a punctuation character.\"\"\"\n",
    "    cp = ord(char)\n",
    "    # We treat all non-letter/number ASCII as punctuation.\n",
    "    # Characters such as \"^\", \"$\", and \"`\" are not in the Unicode\n",
    "    # Punctuation class but we treat them as punctuation anyways, for\n",
    "    # consistency.\n",
    "    if (cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126):\n",
    "        return True\n",
    "    cat = unicodedata.category(char)\n",
    "    if cat.startswith(\"P\"):\n",
    "        return True\n",
    "    return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "code_folding": [
     0
    ],
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for idx,e in enumerate(pred_data_1):\n",
    "    for spo in e['spo_list']:\n",
    "        while spo['subject'][0]=='《' and ( spo['subject'][-1]=='》' or  spo['subject'].find(\"》\")==-1):\n",
    "            print(\"sub\",spo['subject'])\n",
    "            spo['subject']=spo['subject'].replace(\"《\",\"\").replace(\"》\",\"\")\n",
    "            print(\"sub\",spo['subject'])         \n",
    "            break\n",
    "        poped_keys=[]\n",
    "        for key,value in spo['object'].items():\n",
    "            if len(value)==0:\n",
    "                print(spo)\n",
    "                poped_keys.append(key)\n",
    "            if len(poped_keys)>0:\n",
    "                for t in poped_keys:\n",
    "                    print(t)\n",
    "                    spo['object'].pop(t)\n",
    "                    spo['object_type'].pop(t)\n",
    "                print(idx,pred_data_1[idx])\n",
    "                break\n",
    "            while value[0]=='《' and (value[-1]=='》' or value.find(\"》\")==-1):\n",
    "                print(\"ob\",key,value)\n",
    "                spo['object'][key]=value.replace(\"《\",\"\").replace(\"》\",\"\")\n",
    "                print(\"ob\",spo['object'][key])        \n",
    "                break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"./predict_res kg.json\",\"w\") as w:\n",
    "    for e in pred_data_1:\n",
    "        w.write(json.dumps(e, ensure_ascii=False)+'\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16081"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_data_2=[]\n",
    "pred_num_2=0\n",
    "with open(\"./test1_res.json\",\"r\") as r:\n",
    "    raw_data=r.readlines()\n",
    "    for d in raw_data:\n",
    "        pred_data_2.append(json.loads(d))\n",
    "        pred_num_2+=len(pred_data_2[-1]['spo_list'])\n",
    "pred_num_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1: {'object': {'@value': '何逊'}, 'subject': '车中见新林分别甚盛', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '车中见新林分别甚盛', 'object': {'@value': '梁何逊'}}\n",
      "==========\n",
      "1: {'object': {'@value': '唐纳德·特朗普'}, 'subject': '伊万卡·特朗普', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '伊万卡·特朗普', 'object': {'@value': '特朗普'}}\n",
      "==========\n",
      "1: {'object': {'@value': '庆嘉帝龙非离'}, 'subject': '龙无垢', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '龙无垢', 'object': {'@value': '庆嘉帝'}}\n",
      "==========\n",
      "1: {'object': {'@value': '庆嘉帝龙非离'}, 'subject': '龙无垢', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '龙无垢', 'object': {'@value': '龙非离'}}\n",
      "==========\n",
      "1: {'object': {'@value': '北魏孝文帝元宏'}, 'subject': '元恂', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '元恂', 'object': {'@value': '元宏'}}\n",
      "==========\n",
      "1: {'object': {'@value': '昂旺文章'}, 'subject': '唱给雪域的情歌', 'object_type': {'@value': '人物'}, 'predicate': '作词', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '人物'}, 'predicate': '作词', 'subject': '唱给雪域的情歌', 'object': {'@value': '昂旺'}}\n",
      "==========\n",
      "1: {'object': {'@value': '成都高新区金融城'}, 'subject': '成都君海投资咨询有限公司', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject_type': '企业'}\n",
      "2: {'subject_type': '企业', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject': '成都君海投资咨询有限公司', 'object': {'@value': '成都'}}\n",
      "==========\n",
      "1: {'object': {'@value': '东汉末年'}, 'subject': '孙策', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '孙策', 'object': {'@value': '东汉'}}\n",
      "==========\n",
      "1: {'object': {'@value': '梅蒂选'}, 'subject': '梭罗河畔', 'object_type': {'@value': '人物'}, 'predicate': '作曲', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '人物'}, 'predicate': '作曲', 'subject': '梭罗河畔', 'object': {'@value': '梅蒂'}}\n",
      "==========\n",
      "1: {'object': {'@value': '楼钥'}, 'subject': '攻愧集', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '攻愧集', 'object': {'@value': '宋楼钥'}}\n",
      "==========\n",
      "1: {'object': {'@value': '刘侗 于奕正'}, 'subject': '帝京景物略', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '帝京景物略', 'object': {'@value': '刘侗'}}\n",
      "==========\n",
      "1: {'object': {'@value': '马 凌九九'}, 'subject': '流离', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '流离', 'object': {'@value': '凌九九'}}\n",
      "==========\n",
      "1: {'object': {'@value': '中华人民共和国'}, 'subject': '黄勇', 'object_type': {'@value': '国家'}, 'predicate': '国籍', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '国家'}, 'predicate': '国籍', 'subject': '黄勇', 'object': {'@value': '中华'}}\n",
      "==========\n",
      "1: {'object': {'@value': '李咸用'}, 'subject': '同友生春夜闻雨', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '同友生春夜闻雨', 'object': {'@value': '李咸'}}\n",
      "==========\n",
      "1: {'object': {'@value': '战国时期'}, 'subject': '苏秦', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '苏秦', 'object': {'@value': '战国'}}\n",
      "==========\n",
      "1: {'object': {'@value': '战国时期'}, 'subject': '苏代', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '苏代', 'object': {'@value': '战国'}}\n",
      "==========\n",
      "1: {'object': {'@value': '唐高祖李渊'}, 'subject': '真定公主', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '真定公主', 'object': {'@value': '李渊'}}\n",
      "==========\n",
      "1: {'object': {'@value': '安徽广德经济开发区'}, 'subject': '安徽鑫盛汽车制造有限公司', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject_type': '企业'}\n",
      "2: {'subject_type': '企业', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject': '安徽鑫盛汽车制造有限公司', 'object': {'@value': '安徽'}}\n",
      "==========\n",
      "1: {'object': {'@value': '北齐神武皇帝高欢'}, 'subject': '娄昭君', 'object_type': {'@value': '人物'}, 'predicate': '丈夫', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '丈夫', 'subject': '娄昭君', 'object': {'@value': '高欢'}}\n",
      "==========\n",
      "1: {'object': {'@value': '王筠'}, 'subject': '昭明太子哀册文', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '昭明太子哀册文', 'object': {'@value': '梁王筠'}}\n",
      "==========\n",
      "1: {'object': {'@value': '明中'}, 'subject': '李用敬', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '李用敬', 'object': {'@value': '明中期'}}\n",
      "==========\n",
      "1: {'object': {'@value': '9万余人'}, 'subject': '樟木乡', 'object_type': {'@value': 'Number'}, 'predicate': '人口数量', 'subject_type': '行政区'}\n",
      "2: {'subject_type': '行政区', 'object_type': {'@value': 'Number'}, 'predicate': '人口数量', 'subject': '樟木乡', 'object': {'@value': '9万'}}\n",
      "==========\n",
      "1: {'object': {'@value': '伍乐城 rnls'}, 'subject': '多谢失恋', 'object_type': {'@value': '人物'}, 'predicate': '作曲', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '人物'}, 'predicate': '作曲', 'subject': '多谢失恋', 'object': {'@value': '伍乐城'}}\n",
      "==========\n",
      "1: {'object': {'@value': '掘金队'}, 'subject': '丹佛掘金队', 'object_type': {'@value': 'Text'}, 'predicate': '简称', 'subject_type': '机构'}\n",
      "2: {'subject_type': '机构', 'object_type': {'@value': 'Text'}, 'predicate': '简称', 'subject': '丹佛掘金队', 'object': {'@value': '掘金'}}\n",
      "==========\n",
      "1: {'object': {'@value': '江西省南昌市'}, 'subject': '南昌欧菲光科技有限公司', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject_type': '企业'}\n",
      "2: {'subject_type': '企业', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject': '南昌欧菲光科技有限公司', 'object': {'@value': '南昌市'}}\n",
      "==========\n",
      "1: {'object': {'@value': '北京市'}, 'subject': '三里屯', 'object_type': {'@value': '城市'}, 'predicate': '所在城市', 'subject_type': '景点'}\n",
      "2: {'subject_type': '景点', 'object_type': {'@value': '城市'}, 'predicate': '所在城市', 'subject': '三里屯', 'object': {'@value': '北京'}}\n",
      "==========\n",
      "1: {'object': {'@value': '金子与志一'}, 'subject': '人间失格', 'object_type': {'@value': '人物'}, 'predicate': '导演', 'subject_type': '影视作品'}\n",
      "2: {'subject_type': '影视作品', 'object_type': {'@value': '人物'}, 'predicate': '导演', 'subject': '人间失格', 'object': {'@value': '金子'}}\n",
      "==========\n",
      "1: {'object': {'@value': '北京市'}, 'subject': '密云水库', 'object_type': {'@value': '城市'}, 'predicate': '所在城市', 'subject_type': '景点'}\n",
      "2: {'subject_type': '景点', 'object_type': {'@value': '城市'}, 'predicate': '所在城市', 'subject': '密云水库', 'object': {'@value': '北京'}}\n",
      "==========\n",
      "1: {'object': {'@value': '县域医共体'}, 'subject': '县域医疗服务共同体', 'object_type': {'@value': 'Text'}, 'predicate': '简称', 'subject_type': '机构'}\n",
      "2: {'subject_type': '机构', 'object_type': {'@value': 'Text'}, 'predicate': '简称', 'subject': '县域医疗服务共同体', 'object': {'@value': '医共体'}}\n",
      "==========\n",
      "1: {'object': {'@value': '彭辛纳'}, 'subject': '彭湃', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '彭湃', 'object': {'@value': '彭辛'}}\n",
      "==========\n",
      "1: {'object': {'@value': '春秋时代'}, 'subject': '季文子', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '季文子', 'object': {'@value': '春秋'}}\n",
      "==========\n",
      "1: {'object': {'@value': '安旭'}, 'subject': '但愿少爱你一点', 'object_type': {'@value': '人物'}, 'predicate': '歌手', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '人物'}, 'predicate': '歌手', 'subject': '但愿少爱你一点', 'object': {'@value': '安旭叶'}}\n",
      "==========\n",
      "1: {'object': {'@value': '婷婷'}, 'subject': '婷仔', 'object_type': {'@value': '人物'}, 'predicate': '母亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '母亲', 'subject': '婷仔', 'object': {'@value': '“婷婷'}}\n",
      "==========\n",
      "1: {'object': {'@value': '意大利马拉内罗'}, 'subject': '法拉利', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject_type': '企业'}\n",
      "2: {'subject_type': '企业', 'object_type': {'@value': '地点'}, 'predicate': '总部地点', 'subject': '法拉利', 'object': {'@value': '意大利'}}\n",
      "==========\n",
      "1: {'object': {'@value': '网络红人冷兮儿'}, 'subject': '御灵传说之救世主', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '御灵传说之救世主', 'object': {'@value': '冷兮儿'}}\n",
      "==========\n",
      "1: {'object': {'@value': '萧萧 大理石'}, 'subject': '公主的魔法项链', 'object_type': {'@value': '人物'}, 'predicate': '作词', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '人物'}, 'predicate': '作词', 'subject': '公主的魔法项链', 'object': {'@value': '萧萧'}}\n",
      "==========\n",
      "1: {'object': {'@value': '邪神洛基'}, 'subject': '耶梦加得', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '耶梦加得', 'object': {'@value': '洛基'}}\n",
      "==========\n",
      "1: {'object': {'@value': '邪神洛基'}, 'subject': '海拉', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '海拉', 'object': {'@value': '洛基'}}\n",
      "==========\n",
      "1: {'object': {'@value': '孟山人'}, 'subject': '孟浩然', 'object_type': {'@value': 'Text'}, 'predicate': '号', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '号', 'subject': '孟浩然', 'object': {'@value': '孟山'}}\n",
      "==========\n",
      "1: {'object': {'@value': '明仁宗朱高炽'}, 'subject': '嘉兴公主', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '嘉兴公主', 'object': {'@value': '明仁宗'}}\n",
      "==========\n",
      "1: {'object': {'@value': '明仁宗朱高炽'}, 'subject': '嘉兴公主', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '嘉兴公主', 'object': {'@value': '朱高炽'}}\n",
      "==========\n",
      "1: {'object': {'@value': '冯骥才'}, 'subject': '高女人和她的矮丈夫', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '高女人和她的矮丈夫', 'object': {'@value': '冯骥'}}\n",
      "==========\n",
      "1: {'object': {'@value': '夏敢若何'}, 'subject': '爱吃爱喝爱生活', 'object_type': {'@value': '人物'}, 'predicate': '作词', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '人物'}, 'predicate': '作词', 'subject': '爱吃爱喝爱生活', 'object': {'@value': '夏敢若'}}\n",
      "==========\n",
      "1: {'object': {'@value': '中华人民共和国'}, 'subject': '刘禹', 'object_type': {'@value': '国家'}, 'predicate': '国籍', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '国家'}, 'predicate': '国籍', 'subject': '刘禹', 'object': {'@value': '中华'}}\n",
      "==========\n",
      "1: {'object': {'@value': '派克\\\\帕克'}, 'subject': '派克汉尼汾', 'object_type': {'@value': 'Text'}, 'predicate': '简称', 'subject_type': '机构'}\n",
      "2: {'subject_type': '机构', 'object_type': {'@value': 'Text'}, 'predicate': '简称', 'subject': '派克汉尼汾', 'object': {'@value': '派克'}}\n",
      "==========\n",
      "1: {'object': {'@value': '杨端和'}, 'subject': '语言研究应用SPSS软件实例大全', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '语言研究应用SPSS软件实例大全', 'object': {'@value': '杨端'}}\n",
      "==========\n",
      "1: {'object': {'@value': '春秋时期'}, 'subject': '豫让', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '豫让', 'object': {'@value': '春秋'}}\n",
      "==========\n",
      "1: {'object': {'@value': '春秋时期'}, 'subject': '伍子胥', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '伍子胥', 'object': {'@value': '春秋'}}\n",
      "==========\n",
      "1: {'object': {'@value': '潘行紫旻'}, 'subject': '今生永相伴', 'object_type': {'@value': '人物'}, 'predicate': '作曲', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '人物'}, 'predicate': '作曲', 'subject': '今生永相伴', 'object': {'@value': '潘行'}}\n",
      "==========\n",
      "1: {'object': {'@value': '明代'}, 'subject': '虞程', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject_type': '历史人物'}\n",
      "2: {'subject_type': '历史人物', 'object_type': {'@value': 'Text'}, 'predicate': '朝代', 'subject': '虞程', 'object': {'@value': '明'}}\n",
      "==========\n",
      "1: {'object': {'@value': '”金唱片”', 'inWork': '流连', 'onDate': '1982年'}, 'subject': '费翔', 'object_type': {'@value': '奖项', 'inWork': '作品', 'onDate': 'Date'}, 'predicate': '获奖', 'subject_type': '娱乐人物'}\n",
      "2: {'subject_type': '娱乐人物', 'object_type': {'@value': '奖项'}, 'predicate': '获奖', 'subject': '费翔', 'object': {'@value': '金唱片'}}\n",
      "==========\n",
      "1: {'object': {'@value': '纯色角5'}, 'subject': '热浪', 'object_type': {'@value': '音乐专辑'}, 'predicate': '所属专辑', 'subject_type': '歌曲'}\n",
      "2: {'subject_type': '歌曲', 'object_type': {'@value': '音乐专辑'}, 'predicate': '所属专辑', 'subject': '热浪', 'object': {'@value': '纯色角'}}\n",
      "==========\n",
      "1: {'object': {'@value': '辽景宗耶律贤'}, 'subject': '萧绰', 'object_type': {'@value': '人物'}, 'predicate': '丈夫', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '丈夫', 'subject': '萧绰', 'object': {'@value': '耶律贤'}}\n",
      "==========\n",
      "1: {'object': {'@value': '刘烨'}, 'subject': '老男孩', 'object_type': {'@value': '人物'}, 'predicate': '主演', 'subject_type': '影视作品'}\n",
      "2: {'subject_type': '影视作品', 'object_type': {'@value': '人物'}, 'predicate': '主演', 'subject': '老男孩', 'object': {'@value': '搜刘烨'}}\n",
      "==========\n",
      "1: {'object': {'@value': '唐太宗李世民'}, 'subject': '晋阳公主', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '晋阳公主', 'object': {'@value': '李世民'}}\n",
      "==========\n",
      "1: {'object': {'@value': '著名作曲家丁丕业'}, 'subject': '丁铃', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '丁铃', 'object': {'@value': '丁丕业'}}\n",
      "==========\n",
      "1: {'object': {'@value': '郭初永真'}, 'subject': '郭台铭', 'object_type': {'@value': '人物'}, 'predicate': '母亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '母亲', 'subject': '郭台铭', 'object': {'@value': '郭初永'}}\n",
      "==========\n",
      "1: {'object': {'@value': '陆定原'}, 'subject': '陆小曼', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject_type': '人物'}\n",
      "2: {'subject_type': '人物', 'object_type': {'@value': '人物'}, 'predicate': '父亲', 'subject': '陆小曼', 'object': {'@value': '陆定'}}\n",
      "==========\n",
      "1: {'object': {'@value': '于程雷'}, 'subject': '中国梦之声', 'object_type': {'@value': '人物'}, 'predicate': '主持人', 'subject_type': '电视综艺'}\n",
      "2: {'subject_type': '电视综艺', 'object_type': {'@value': '人物'}, 'predicate': '主持人', 'subject': '中国梦之声', 'object': {'@value': '程雷'}}\n",
      "==========\n",
      "1: {'object': {'@value': '从维熙'}, 'subject': '走向混沌·混沌之初到第十三名', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '走向混沌·混沌之初到第十三名', 'object': {'@value': '维熙'}}\n",
      "==========\n",
      "1: {'object': {'@value': '季恒恒点校'}, 'subject': '钦定廓尔喀纪略', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject_type': '图书作品'}\n",
      "2: {'subject_type': '图书作品', 'object_type': {'@value': '人物'}, 'predicate': '作者', 'subject': '钦定廓尔喀纪略', 'object': {'@value': '季恒恒'}}\n",
      "==========\n"
     ]
    }
   ],
   "source": [
    "def cross_contain(a,b):\n",
    "    if a.find(b)!=-1 or b.find(a)!=-1:\n",
    "        return True\n",
    "    return False\n",
    "for idx in range(len(pred_data_1)):\n",
    "    for spo in pred_data_2[idx]['spo_list']:\n",
    "        flag=True\n",
    "        for temp in pred_data_1[idx]['spo_list']:\n",
    "            if temp['subject']==spo['subject'] and temp['predicate']==spo['predicate']  and cross_contain(temp['object']['@value'],spo['object']['@value'])\\\n",
    "               and temp['object']['@value']!=spo['object']['@value'] and len(spo['object']['@value'])<4:\n",
    "                flag=False\n",
    "                print(\"1:\",temp)\n",
    "                print(\"2:\",spo)\n",
    "                print(\"=\"*10)\n",
    "#         if flag:\n",
    "#             pred_data_1[idx]['spo_list'].append(spo)\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fjw",
   "language": "python",
   "name": "fjw"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
